home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-08 | 11.7 KB | 406 lines | [TEXT/MPS ] |
- /*
- File: FrameInfo.cpp
-
- Contains: FrameInfo utility class
-
- Written by: Steve Smith
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (ie. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // --- FrameInfo Includes ---
-
- #ifndef _FRAMEINFO_
- #include "FrameInfo.h"
- #endif
-
- #ifndef _PANELEDITORDEF_
- #include "PanelEditorDef.h"
- #endif
-
- // --- OpenDoc Includes ---
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _ODNEW_
- #include <ODNew.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #pragma segment PanelEditorFramInfo
-
- //=========================================================================
- // CFrameInfo
- //=========================================================================
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CFrameInfo
- //-------------------------------------------------------------------------
-
- CFrameInfo::CFrameInfo(ODSession* session)
- {
- fSession = session;
- fFrameActive = kODFalse;
- fFrameReactivate = kODFalse;
- fShouldDisposeWindow = kODFalse;
- fActiveFacet = kODNULL;
- fSourceFrame = kODNULL;
- fDependentFrame = kODNULL;
- fPartWindowID = kODNULLID;
- fPreviousViewType = kODNullTypeToken;
- fShouldNegotiate = kODFalse;
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::~CFrameInfo
- //-------------------------------------------------------------------------
-
- CFrameInfo::~CFrameInfo()
- {
- // Deleting the proxies will release the encapsulated frames.
- ODDeleteObject(fDependentFrame);
- ODDeleteObject(fSourceFrame);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::Externalize
- //-------------------------------------------------------------------------
-
- void CFrameInfo::Externalize(Environment* ev, ODStorageUnitView* storageUnitView)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
-
- this->CleanseFrameInfoProperty(ev, storageUnit);
- this->ExternalizeFrameInfo(ev, storageUnit, kODNULLKey, kODNULL);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CleanseFrameInfoProperty
- //-------------------------------------------------------------------------
-
- void CFrameInfo::CleanseFrameInfoProperty(Environment* ev, ODStorageUnit* storageUnit)
- {
- ODULong numValues;
- ODULong index;
-
- numValues = storageUnit->CountValues(ev);
-
- for (index = numValues; index >= 1; index--)
- {
- // Index, from 1 to n, through the values.
- storageUnit->Focus(ev, kODNULL, kODPosSame,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The temp object
- // will automatically delete the returned value when this
- // scope is exited.
- TempODValueType value = storageUnit->GetType(ev);
-
- // If the value type is not one we support, remove it.
- if ( ODISOStrCompare(value, kPanelEditorInfo) != 0 )
- storageUnit->Remove(ev);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::ExternalizeFrameInfo
- //-------------------------------------------------------------------------
-
- void CFrameInfo::ExternalizeFrameInfo(Environment* ev, ODStorageUnit* storageUnit,
- ODDraftKey key, ODFrame* scopeFrame)
- {
- // This method behaves much the same way as the SamplePart::ExternalizeStateInfo
- // method.
-
- if ( storageUnit->Exists(ev, kODNULL, kPanelEditorInfo, 0) )
- {
- // Persistent object references are stored in a side table, rather than
- // in the property/value stream. Thus, deleting the contents of a value
- // will not "delete" the references previously written to that value. To
- // completely "delete" all references written to the value, we must
- // remove the value and add it back.
-
- storageUnit->Focus(ev, kODNULL, kODPosSame, kPanelEditorInfo, 0, kODPosUndefined);
- storageUnit->Remove(ev);
- }
-
- // Add a value to write the data into.
- storageUnit->AddValue(ev, kPanelEditorInfo);
-
- // Write a weak reference to our source frame.
- {
- ODStorageUnitRef weakRef = {0,0,0,0};
-
- if ( fSourceFrame )
- {
- ODID frameID = fSourceFrame->GetID();
- ODID scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
- ODDraft* fromDraft = fSourceFrame->GetDraft();
-
- // If a draft key exists, then we are being cloned to another draft.
- // We must "weak" clone our display frame and reference the cloned
- // frame. The part re-uses the frameID variable so there aren't two
- // different GetWeakStorageUnitRef calls.
- if ( key )
- frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
-
- // Write out weak references to each of the part's display frames.
- storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
- }
- StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
- }
-
- // Write a weak reference to our dependent frame.
- {
- ODStorageUnitRef weakRef = {0,0,0,0};
-
- if ( fDependentFrame )
- {
- ODID frameID = fDependentFrame->GetID();
- ODID scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
- ODDraft* fromDraft = fDependentFrame->GetDraft();
-
- // If a draft key exists, then we are being cloned to another draft.
- // We must "weak" clone our display frame and reference the cloned
- // frame. The part re-uses the frameID variable so there aren't two
- // different GetWeakStorageUnitRef calls.
- if ( key )
- frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
-
- // Write out weak references to each of the part's display frames.
- storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
- }
- StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CloneInto
- //-------------------------------------------------------------------------
-
- void CFrameInfo::CloneInto(Environment *ev, ODDraftKey key,
- ODStorageUnitView* storageUnitView, ODFrame* scopeFrame)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
-
- if ( storageUnit->Exists(ev, kODNULL, kPanelEditorInfo, 0) == kODFalse )
- {
- this->ExternalizeFrameInfo(ev, storageUnit, key, scopeFrame);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::InitFromStorage
- //------------------------------------------------------------------------------
-
- void CFrameInfo::InitFromStorage(Environment* ev, ODStorageUnitView* storageUnitView)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
-
- if ( storageUnit->Exists(ev, kODNULL, kPanelEditorInfo, 0) )
- {
- TRY
- storageUnit->Focus(ev, kODNULL, kODPosSame,
- kPanelEditorInfo, 0 , kODPosUndefined);
-
- ODStorageUnitRef weakRef = {0,0,0,0};
- StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
- (ODPtr)&weakRef);
-
- if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
- {
- // Convert the reference into a runtime id.
- ODID frameID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
-
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = new CFrameProxy;
- proxy->InitFrameProxy(frameID, ODGetDraft(ev,storageUnit));
-
- // Store the proxy source frame.
- fSourceFrame = proxy;
- }
-
- CATCH_ALL
- ODDeleteObject(fSourceFrame);
- fSourceFrame = kODNULL;
- // We do not RERAISE because the reference is weak and therefore
- // we cannot rely on its existence.
- ENDTRY
-
- TRY
- ODStorageUnitRef weakRef = {0,0,0,0};
- StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
- (ODPtr)&weakRef);
-
- if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
- {
- // Convert the reference into a runtime id.
- ODID frameID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
-
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = new CFrameProxy;
- proxy->InitFrameProxy(frameID, ODGetDraft(ev,storageUnit));
-
- // Store the proxy dependent frame.
- fDependentFrame = proxy;
- }
-
- CATCH_ALL
- ODDeleteObject(fDependentFrame);
- fDependentFrame = kODNULL;
- // We do not RERAISE because the reference is weak and therefore
- // we cannot rely on its existence.
- ENDTRY
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::SetSourceFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::SetSourceFrame(Environment* ev, ODFrame* frame)
- {
- if ( frame != kODNULL )
- {
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = new CFrameProxy;
- proxy->InitFrameProxy(ev,frame);
-
- // Store the proxy source frame after clearing the old one.
- ODDeleteObject(fSourceFrame);
- fSourceFrame = proxy;
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::ReleaseSourceFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::ReleaseSourceFrame(Environment* ev)
- {
- ODDeleteObject(fSourceFrame);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::SetDependentFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::SetDependentFrame(Environment* ev, ODFrame* frame)
- {
- if ( frame != kODNULL )
- {
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = new CFrameProxy;
- proxy->InitFrameProxy(ev,frame);
-
- // Store the proxy dependent frame after clearing the old one.
- ODDeleteObject(fDependentFrame);
- fDependentFrame = proxy;
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::ReleaseDependentFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::ReleaseDependentFrame(Environment* ev)
- {
- ODDeleteObject(fDependentFrame);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::AcquirePartWindow
- //-------------------------------------------------------------------------
-
- ODWindow* CFrameInfo::AcquirePartWindow(Environment* ev)
- {
- ODWindow* window = kODNULL;
-
- if ( fPartWindowID )
- {
- window = fSession->GetWindowState(ev)->AcquireWindow(ev,fPartWindowID);
- if ( !window) fPartWindowID = kODNULLID;
- }
-
- return window;
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::SetPartWindow
- //-------------------------------------------------------------------------
-
- void CFrameInfo::SetPartWindow(Environment* ev, ODWindow* window)
- {
- fPartWindowID = window ? window->GetID(ev) : kODNULLID;
- }
-
-
-